//
//  ForgetPasswordViewViewController.swift
//  XGamesLive
//
//  Created by ios on 2024/5/14.
//

import UIKit
import MXCommonModule

class ForgetPasswordViewViewController: UIViewController,CustomNavgationBar{
    lazy var hudView: XGL_CustomHudView = XGL_CustomHudView()
    var forgetView: ForgetPasswordView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.createCustomBackgroundView()
        self.forgetView = ForgetPasswordView().then({ make in
            make.delegate = self
        })
        self.view.addSubview(self.forgetView)
        self.forgetView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        self.creatClearNavigationBar(title: "Forget Password")
    }

}

extension ForgetPasswordViewViewController: ForgetPasswordDelegate{
    func getCode() {
        self.getCodeRequest()
    }
    
    func createAccount() {
        let vc = LoginCreateAccountViewController()
        self.navigationController?.pushViewController(vc)
    }
    
    func nextStep() {
        guard self.forgetView.email.isEmpty == false else {
            MXProgressHUD.hudWithText("Please enter email")
            return
        }
        guard self.forgetView.code.isEmpty == false else {
            MXProgressHUD.hudWithText("Please enter code")
            return
        }
//        let vc = ResetNewPasswordViewController()
//        self.navigationController?.pushViewController(vc)
        self.verifyCodeRequest()
    }
    
}

extension ForgetPasswordViewViewController{
    func getCodeRequest(){
        self.hudView.backgroundColor = .clear
        self.hudView.hudView.backgroundColor = .clear
        self.hudView.hudView.startAnimation()
        self.view.addSubview(self.hudView)
        self.hudView.snp.makeConstraints { make in
            make.width.centerX.bottom.equalToSuperview()
            make.top.equalTo(PanNavibarH)
        }
        PanRequestManager<XGL_RequestBaseResponse<Response>,XGL_CustomRequestError>().request(CustomRequestAPI(requestAPI: .fakeRequest(strContent: "2048", intContent: nil))) { result in
            self.hudView.dismiss()
            switch result{
            case .success(let response):
                
                break
            default:
                break
            }
        }
    }
    
    func verifyCodeRequest(){
        self.hudView.hudView.startAnimation()
        self.view.addSubview(self.hudView)
        self.hudView.snp.makeConstraints { make in
            make.width.centerX.bottom.equalToSuperview()
            make.top.equalTo(PanNavibarH)
        }
        PanRequestManager<XGL_RequestBaseResponse<Response>,XGL_CustomRequestError>().request(CustomRequestAPI(requestAPI: .fakeRequest(strContent: "2048", intContent: nil))) { result in
            self.hudView.dismiss()
            switch result{
            case .success(let response):
                MXProgressHUD.hudWithText("Verification code error ~")
                break
            default:
                break
            }
        }
    }
}
